package com.feiyu.admin.service.impl;

import org.springframework.stereotype.Service;

import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.feiyu.common.utils.PageUtils;
import com.feiyu.common.utils.Query;

import com.feiyu.admin.dao.ShopDao;
import com.feiyu.admin.entity.ShopEntity;
import com.feiyu.admin.service.ShopService;


@Service("shopService")
public class ShopServiceImpl extends ServiceImpl<ShopDao, ShopEntity> implements ShopService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<ShopEntity> wrapper = new QueryWrapper<>();
        if (params.get("shopType") != "" && params.get("fuzzyKey") == "") {
            wrapper.eq("shop_type", params.get("shopType"));
        } else if (params.get("shopType") == "" && params.get("fuzzyKey") != "") {
            wrapper.like("shop_name", params.get("fuzzyKey"));
        } else if(params.get("shopType") != "" && params.get("fuzzyKey") != ""){
            wrapper.eq("shop_type", params.get("shopType"))
                    .like("shop_name", params.get("fuzzyKey"));
        }
        IPage<ShopEntity> page = this.page(
                new Query<ShopEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

}